package com.yfj.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yfj.dao.ShiroDao;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yfj.entity.Course;
import com.yfj.service.ManagerService;

@Controller
public class PublicController {

    @Autowired
    ShiroDao shiroDao;

    @RequestMapping("changePassword")
    public String changePassword(){
        return "changePassword";
    }

    @RequestMapping("/confirmOriginPW")
    @ResponseBody
    public int confirmOrigin(String id,String orignPW){
        int mark=0;
        //浏览器传来的密码加密转换
        Md5Hash md5Hash=new Md5Hash(orignPW,"megalovania");
        String password1=md5Hash.toString();
        //获取数据库里该id的密码
        String password2=shiroDao.getPassWordByUserName(id);
        if(password1.equals(password2)){
            mark=1;
        }
        return mark;
    }
    @RequestMapping("/modifyPW")
    @ResponseBody
    public int modifyPW(String id,String identity,String newPW){
        System.out.println(id+" "+identity+" "+newPW);
        int mark=0;
        Md5Hash md5Hash=new Md5Hash(newPW,"megalovania");
        String pw=md5Hash.toString();
        try {
            shiroDao.updatePassWordByUserName(id,identity,pw);
            mark=1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mark;
    }
}
